package com.yuetong.business.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.yuetong.common.annotation.Log;
import com.yuetong.common.core.controller.BaseController;
import com.yuetong.common.core.domain.AjaxResult;
import com.yuetong.common.enums.BusinessType;
import com.yuetong.business.domain.YtContractInfo;
import com.yuetong.business.service.IYtContractInfoService;
import com.yuetong.common.utils.poi.ExcelUtil;
import com.yuetong.common.core.page.TableDataInfo;

/**
 * 合同信息Controller
 *
 * @author  卓晓君
 * @date 2025-03-07
 */
@RestController
@RequestMapping("/business/contract")
public class YtContractInfoController extends BaseController
{
    @Autowired
    private IYtContractInfoService ytContractInfoService;

    /**
     * 查询合同信息列表
     */
    @PreAuthorize("@ss.hasPermi('business:contract:list')")
    @GetMapping("/list")
    public TableDataInfo list(YtContractInfo ytContractInfo)
    {
        startPage();
        List<YtContractInfo> list = ytContractInfoService.selectYtContractInfoList(ytContractInfo);
        return getDataTable(list);
    }

    /**
     * 导出合同信息列表
     */
    @PreAuthorize("@ss.hasPermi('business:contract:export')")
    @Log(title = "合同信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, YtContractInfo ytContractInfo)
    {
        List<YtContractInfo> list = ytContractInfoService.selectYtContractInfoList(ytContractInfo);
        ExcelUtil<YtContractInfo> util = new ExcelUtil<YtContractInfo>(YtContractInfo.class);
        util.exportExcel(response, list, "合同信息数据");
    }

    /**
     * 获取合同信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:contract:query')")
    @GetMapping(value = "/{contractId}")
    public AjaxResult getInfo(@PathVariable("contractId") Long contractId)
    {
        return success(ytContractInfoService.selectYtContractInfoByContractId(contractId));
    }

    /**
     * 新增合同信息
     */
    @PreAuthorize("@ss.hasPermi('business:contract:add')")
    @Log(title = "合同信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody YtContractInfo ytContractInfo)
    {
        return toAjax(ytContractInfoService.insertYtContractInfo(ytContractInfo));
    }

    /**
     * 修改合同信息
     */
    @PreAuthorize("@ss.hasPermi('business:contract:edit')")
    @Log(title = "合同信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody YtContractInfo ytContractInfo)
    {
        return toAjax(ytContractInfoService.updateYtContractInfo(ytContractInfo));
    }

    /**
     * 删除合同信息
     */
    @PreAuthorize("@ss.hasPermi('business:contract:remove')")
    @Log(title = "合同信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{contractIds}")
    public AjaxResult remove(@PathVariable Long[] contractIds)
    {
        return toAjax(ytContractInfoService.deleteYtContractInfoByContractIds(contractIds));
    }
}
